package lex.explorer.file;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import org.lex.explorer.FileInfo;
import org.lex.utils.text.SizeFormat;


public class SizeRenderer extends DefaultTableCellRenderer
{
	public SizeRenderer()
	{
		super();
		this.setHorizontalAlignment( JLabel.RIGHT );
	}

	@Override
	public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected,
		boolean hasFocus, int row, int column )
	{
		FileInfo file = (FileInfo) value;
		String text = "";
		if( file.isFile() )
			text = SizeFormat.autoFormat( file.getSize() ) + "B";
		this.setFont( table.getFont() );
		this.setText( text );
		return this;
	}
}
